package com.fuyun.rpc.client.autoconfigure;

import com.fuyun.rpc.client.annotations.RpcConsumerBootstrap;
import com.fuyun.rpc.client.config.RegistryConfig;
import com.fuyun.rpc.client.config.RpcApplication;
import com.fuyun.rpc.client.config.RpcConfig;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: zrq1351
 * @date: 2025/2/18
 */
@Configuration
@EnableConfigurationProperties({RpcConfig.class, RegistryConfig.class})
public class FuyunRpcClientAutoConfigure {

	@Bean
	@ConditionalOnMissingBean(MeterRegistry.class)
	public MeterRegistry noopMeterRegistry() {
		return new SimpleMeterRegistry();
	}

	@Bean
	public RpcConsumerBootstrap rpcProviderBootstrap(RpcConfig rpcConfig, RegistryConfig registryConfig) {
		RpcApplication rpcApplication = new RpcApplication(rpcConfig, registryConfig);
		rpcApplication.init();
		return new RpcConsumerBootstrap(rpcApplication);
	}

}